import 'package:ad_common/util/pretty_printer.dart';
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';

/// FileName log
/// @Author zhuqingfang
/// @Date 2022/11/2 17:43
/// @Description log
class Log{
  static final logger = Logger(
    level:Level.info,
    output: AdConsoleOutput(),
    printer:MicrocosmPrettyPrinter(
        // printer: PrettyPrinter(
        //因为包了几层，前面信息不显示
          stackTraceBeginIndex: 4,
          //显示最近连续的方法
          methodCount: 1,
          printTime: true),
  );

  static void d(Object msg, [dynamic error, StackTrace? stackTrace]) {
    logger.d(msg, error, stackTrace);
  }

  static void i(Object msg, [dynamic error, StackTrace? stackTrace]) {
    logger.i(msg, error, stackTrace);
  }

  static void e(Object msg, [dynamic error, StackTrace? stackTrace]) {
    logger.e(msg, error, stackTrace);
  }

  static void w(Object msg, [dynamic error, StackTrace? stackTrace]) {
    logger.w(msg, error, stackTrace);
  }
}
class AdConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    final msg = event.lines.join('\n');
    // ignore: avoid_print
    // print(msg);
    debugPrint(msg);
  }
}